home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / plugins / test_prompt.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  4.6 KB  |  135 lines

  1. #
  2. # This file is part of Checkbox.
  3. #
  4. # Copyright 2008 Canonical Ltd.
  5. #
  6. # Checkbox is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Checkbox is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. from checkbox.properties import List, String
  20. from checkbox.plugin import Plugin
  21. from checkbox.test import TestResult, SKIP
  22. from checkbox.traverser import Traverser, TraverserCallbacks
  23.  
  24.  
  25. class PromptTestCallbacks(TraverserCallbacks):
  26.  
  27.     def __init__(self, plugin):
  28.         super(PromptTestCallbacks, self).__init__()
  29.         self._plugin = plugin
  30.  
  31.     def get_architecture(self):
  32.         return self._plugin.architecture
  33.  
  34.     def get_category(self):
  35.         return self._plugin.category
  36.  
  37.     def get_priorities(self):
  38.         return self._plugin.priorities
  39.  
  40.     def skipped_dependent(self, test, result):
  41.         result = TestResult(test, status=SKIP,
  42.             data="Test dependent on skipped test.")
  43.         self._plugin._manager.reactor.fire("report-result", result)
  44.  
  45.     def failed_dependent(self, test, result):
  46.         result = TestResult(test, status=SKIP,
  47.             data="Test dependent on failed test.")
  48.         self._plugin._manager.reactor.fire("report-result", result)
  49.  
  50.     def unsupported_requires(self, test, result):
  51.         result = TestResult(test, status=SKIP,
  52.             data="System does not meet test requirements.")
  53.         self._plugin._manager.reactor.fire("report-result", result)
  54.  
  55.     def undefined_architecture(self, test, result):
  56.         result = TestResult(test, status=SKIP,
  57.             data="No system architecture defined.")
  58.         self._plugin._manager.reactor.fire("report-result", result)
  59.  
  60.     def unsupported_architecture(self, test, result):
  61.         result = TestResult(test, status=SKIP,
  62.             data="System architecture not supported.")
  63.         self._plugin._manager.reactor.fire("report-result", result)
  64.  
  65.     def undefined_category(self, test, result):
  66.         result = TestResult(test, status=SKIP,
  67.             data="No system category defined.")
  68.         self._plugin._manager.reactor.fire("report-result", result)
  69.  
  70.     def unsupported_category(self, test, result):
  71.         result = TestResult(test, status=SKIP,
  72.             data="System category not supported.")
  73.         self._plugin._manager.reactor.fire("report-result", result)
  74.  
  75.  
  76. class PromptTest(Plugin):
  77.  
  78.     # Plugin priorities for running tests
  79.     plugin_priorities = List(type=String(), default_factory=lambda:"manual")
  80.  
  81.     def register(self, manager):
  82.         super(PromptTest, self).register(manager)
  83.         self._tests = []
  84.         self._result = None
  85.         self._traverser = None
  86.  
  87.         self.architecture = None
  88.         self.category = None
  89.         self.priorities = self.plugin_priorities
  90.  
  91.         for (rt, rh) in [
  92.              ("report-architecture", self.report_architecture),
  93.              ("report-category", self.report_category),
  94.              ("report-result", self.report_result),
  95.              ("test-.*", self.test_all),
  96.              ("prompt-tests", self.prompt_tests)]:
  97.             self._manager.reactor.call_on(rt, rh)
  98.  
  99.         self._manager.reactor.call_on("prompt-test-.*",
  100.             self.prompt_test, 100)
  101.  
  102.     def report_architecture(self, architecture):
  103.         self.architecture = architecture
  104.  
  105.     def report_category(self, category):
  106.         self.category = category
  107.  
  108.     def report_result(self, result):
  109.         self._result = result
  110.  
  111.     def test_all(self, test):
  112.         self._tests.append(test)
  113.  
  114.     def prompt_test(self, interface, test):
  115.         if not self._result or self._result.test != test:
  116.             result = TestResult(test, status=SKIP,
  117.                 data="Test not handled by any plugin.")
  118.             self._manager.reactor.fire("report-result", result)
  119.  
  120.     def prompt_tests(self, interface):
  121.         if not self._traverser:
  122.             self._traverser = Traverser(self._tests, PromptTestCallbacks, self)
  123.  
  124.         while True:
  125.             try:
  126.                 test = self._traverser.go(interface.direction, self._result)
  127.             except StopIteration:
  128.                 break
  129.  
  130.             self._manager.reactor.fire("prompt-test-%s" % test.plugin, interface,
  131.                 test)
  132.  
  133.  
  134. factory = PromptTest
  135.